﻿//COMMONFUN.JS
checkBrowse();
var FloatBox=function()
{
};
FloatBox.prototype=
{
    initialize:function(parent)
    {
    this.parent=parent;
    }
,create:function(child,params)
{
    var cfg={x:0,y:0};
    Object.extend(cfg,params,true);
    var div=this.createDiv('dragContainer',cfg.x,cfg.y);
    if(typeof(child)=='string') div.innerHTML=child;
    else if(typeof(child)=='object') div.appendChild(child);
    else
    {
        return false;
    }
    this.dragBox=this.parent.appendChild(div);
    if(params&&params.type&&params.type=='swf')
    {
        this.dragBoxPoint=this.dragBox.appendChild(this.createDiv('dragPoint',0,0,20,20,100));
        this.dragBoxPoint.style.backgroundColor='#FF0000';
    }
    else
    {
        this.dragBoxPoint=this.dragBox;
    }
    this.dragBoxPoint.onmousedown=this.box_mousedown.bindAsEventListener(this);
}
,createAdPreview:function(parent,src,w,h,x,y)
{
    this.initialize(parent);
    var obj=this.getAdHtml(src,w,h);
    if(!obj)
    {
        return false;
    }
    var htmlStr=obj.html;
    var params=
    {
        type:obj.type
    };
    if(x&&y)
    {
        params.x=x;
        params.y=y;
    }
    this.create(htmlStr,params);
}
,box_mousedown:function(evt)
{
    if(!evt) evt=window.event;
    var d=document;
    var x=evt.clientX-this.dragBox.offsetLeft;
    var y=evt.clientY-this.dragBox.offsetTop;
    var _this=this;
    if(_this.dragBox.setCapture)this.dragBox.setCapture();
    else if(window.captureEvents)window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
    d.onmousemove=function(evt)
    {
        if(!evt) evt=window.event;
        _this.dragBox.style.left=evt.clientX-x;
        _this.dragBox.style.top=evt.clientY-y;
    };
    d.onmouseup=function(evt)
    {
        if(!evt) evt=window.event;
        if(_this.dragBox.releaseCapture)_this.dragBox.releaseCapture();
        else if(window.captureEvents)window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
        d.onmousemove=null;
        d.onmouseup=null;
        if(_this.mymouseup) _this.mymouseup(evt);
    };
    evt.cancelBubble=true;
    return false;
}
,setEvent:function(eventType,fun)
{
    switch(eventType)
    {
        case 'onmousedown':this.mymousedown=function(evt)
        {
            fun(evt);
        };
        break;
        case 'onmousemove':this.mymousemove=function(evt)
        {
            fun(evt);
        };
        break;
        case 'onmouseup':this.mymouseup=function(evt)
        {
            fun(evt);
        };
        break;
        default:break;
    }
}
,getPos:function()
{
    var x=this.dragBox.offsetLeft;
    var y=this.dragBox.offsetTop;
    return{x:x,y:y};
}
,getAdHtml:function(src,w,h)
{
    var ext=src.substring(src.lastIndexOf('.')+1,src.length).toLowerCase();
    var str='';
    if(ext=='png')
    {
        str='<div width='+w+'px height='+h+'px style="position:absolute;left:-'+parseInt(w/2)+'px;top:-'+parseInt(h/2)+'px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+src+',sizingMethod=scale);width:'+w+'px;height:'+h+'px;cursor:pointer;"></div>';
    }
    else if(ext=='swf')
    {
        str='<div style="position:absolute;left:-'+parseInt(w/2)+'px;top:-'+parseInt(h/2)+'px;"><object _ad=1 classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+w+'" height="'+h+'"> <param name="movie" value="'+src+'"> <param name="quality" value="high"> <param name="wmode" value="transparent"> <embed src="'+src+'" width="'+w+'" height="'+h+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed></div>';
    }
    else if(ext=='gif'||ext=='jpg')
    {
        str='<img src="'+src+'" width='+w+'px height='+h+'px style="position:absolute;left:-'+parseInt(w/2)+'px;top:-'+parseInt(h/2)+'px;width:'+w+'px;height:'+h+'px;cursor:pointer">';
    }
    else
    {
        return null;
    }
    return{html:str,type:ext};
}
,createDiv:function(id,left,top,width,height,z,type)
{
    left=left?left:0;
    top=top?top:0;
    var elm=document.createElement('div');
    elm.id=id;
    elm.style.left=left+'px';
    elm.style.top=top+'px';
    if(z) elm.style.zIndex=z;
    if(width) elm.style.width=width+'px';
    if(height) elm.style.height=height+'px';
    elm.style.position=type?'relative':'absolute';
    return elm;
    }
};